const { ccclass, property } = cc._decorator;

@ccclass
export default class playerDataInfo extends cc.Component {
    static gameData = {};
    static initData() {
        playerDataInfo.gameData = {};
        let playerLevel = playerDataInfo.getGameData("playerLevel");//玩家攻击等级
        let level = playerDataInfo.getGameData("level");//关卡等级
        let attackNum = playerDataInfo.getGameData("attackNum");//攻击力
        let coin = playerDataInfo.getGameData("coin");//金币
        let unLockEnemyPlane = playerDataInfo.getGameData("unLockEnemyPlane");//解锁敌机
        let tiLi = playerDataInfo.getGameData("tiLi");//体力值
        let lifeNum = playerDataInfo.getGameData("lifeNum");//生命值
        let bulletType = playerDataInfo.getGameData("bulletType");//子弹类型
        let bulletLevel = playerDataInfo.getGameData("bulletLevel");//子弹等级

        if (!playerLevel) playerLevel = 1;
        playerDataInfo.setGameDataByKey("playerLevel", playerLevel);

        if (!level) level = 1;
        playerDataInfo.setGameDataByKey("level", level);

        if (!attackNum) attackNum = 1;
        playerDataInfo.setGameDataByKey("attackNum", attackNum);

        if (!coin) coin = 1;
        playerDataInfo.setGameDataByKey("coin", coin);

        if (!unLockEnemyPlane) unLockEnemyPlane = 1;
        playerDataInfo.setGameDataByKey("unLockEnemyPlane", unLockEnemyPlane);

        if (!tiLi) tiLi = 1;
        playerDataInfo.setGameDataByKey("tiLi", tiLi);

        if (!lifeNum) lifeNum = 3;
        playerDataInfo.setGameDataByKey("lifeNum", lifeNum);

        if (!bulletType) bulletType = 0;
        playerDataInfo.setGameDataByKey("bulletType", bulletType);

        if (!bulletLevel) bulletLevel = 0;
        playerDataInfo.setGameDataByKey("bulletLevel", bulletLevel);
    }

    static getGameData(key) {
        let value = cc.sys.localStorage.getItem(key);
        return value;
    }

    static setGameDataByKey(key, value) {
        this.gameData[key] = value;
        cc.sys.localStorage.setItem(key, value);
    }
}
